﻿@{
    ViewBag.Title = "RoleList";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@using Agro.Web;
@section head {
    @if (false) {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        $(document).ready(function () {
            funGridInit();
        });
        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }

        function DeleteRole() {
            $.funListDelete(gridId, "Role_ID", '@Url.Content("~/SystemManage/Role/Delete_Role")');
        }
        function editRole(type) {
            if ('@ViewBag.IsAdmin'!='1') return;
            //根据type的参数 进行设置
            var u = "/SystemManage/Role/RoleDetail?id=";
            if (type == "edit")
                u = "/SystemManage/Role/RoleDetail?id=" + selectId;
            parent.asyncbox.open({
                url: u,
                data: '',
                title: type == "add" ? "新增" : "编辑",
                width: 520,
                height: 350,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action) {
                    var t = this;
                    if (action == 'ok') {
                        DialogFrame($(this).attr("id")).Save(t);
                        return false;
                    }
                    if (action == 'cancel') {

                    }
                    if (action == 'close') {

                    }
                }
            });
        }

        function setRoleActions() {
            var id = jqGridHelper.getSelRowData(gridId, "Role_ID");
            u = "/SystemManage/Role/RoleAction/" + id;
            if (id != null) {
                parent.asyncbox.open({
                    url: u,
                    data: '',
                    title: "角色-操作权限",
                    width: 500,
                    height: 450,
                    scroll: 'no',
                    modal: true,
                    btnsbar: parent.$.btn.OK, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                    callback: function (action) {
                        var t = this;
                        if (action == 'ok') {
//                            DialogFrame($(this).attr("id")).Save(t);
//                            return false;
                        }
                        if (action == 'cancel') {

                        }
                    }
                });
            }
            else {
                alert('没有选中的数据');
            }
        }


        function setRoleUsers() {
            //给角色添加用户
            var id = jqGridHelper.getSelRowData(gridId, "Role_ID");
            u = "/SystemManage/Role/RoleUsers?RoleId=" + id;
            if (id != null) {
                parent.asyncbox.open({
                    url: u,
                    data: '',
                    title: "角色-用户",
                    width: 520,
                    height: 350,
                    scroll: 'no',
                    modal: true,
                    btnsbar: parent.$.btn.OK, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                    callback: function (action) {
                        var t = this;
                        if (action == 'ok') {
                            return;
                        }
                        if (action == 'cancel') {

                        }
                    }
                });
            }
            else {
                alert('没有选中的数据');
            }
        }

        function setRolePermission() {
            //给角色添加功能权限
            var id = jqGridHelper.getSelRowData(gridId, "Role_ID");
            u = "/SystemManage/Role/RolePermissionList?RoleId=" + id;
            if (id != null) {
                parent.asyncbox.open({
                    url: u,
                    data: '',
                    title: "角色-菜单权限",
                    width: 520,
                    height: 350,
                    scroll: 'no',
                    modal: true,
                    btnsbar: parent.$.btn.OK, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                    callback: function (action, opener) {
                        if (action == 'ok') {

                            return ;
                        }
                        if (action == 'cancel') {

                        }
                    }
                });
            }
            else {
                alert('没有选中的数据');
            }
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '@Url.Content("~/SystemManage/Role/GetRoleList")',
                autowidth: false,
                datatype: "json",
                sortname: 'Role_ID',
                sortorder: 'desc',
                colModel: [
                { label: '角色编号', name: 'Role_Code', width: 100 },
                { label: '角色名称', name: 'Role_Name', width: 120 },
                { label: '描述', name: 'Role_Description', width: 200, align: 'center' },
                { label: '是否有效', name: 'Role_IsAvailable', width: 120, formatter: 'YNFmatter', align: 'center' },
                //{ label: '是否内置角色', name: 'Role_IsInnerRole', width: 120, formatter: 'select', editoptions: { value: '1:是;0:否' }, align: 'center' },
                {label: '创建时间', name: 'Role_CreateDate', width: 100 },
                { hidden: true, name: 'Role_ID' }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    selectId = $(gridId).getCell(rowid, "Role_ID");
                },
                ondblClickRow: function (rowid) {
                    if (rowid >= 0)
                        editRole('edit');
                },
                beforeRequest: function (d) {
                    // $(gridId).jqGrid('setGridParam', { postData: data });
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
    </script>
}
<!--头部导航,不用时可以去掉-->
<div class="ui-layout-north">
    <div id="headertitle">
    </div>
    <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
        @Html.ButtonExt("用户", "group_key.png", "Role_Users", "setRoleUsers();")
        @Html.ButtonExt("菜单权限", "group_key.png", "Role_Permission", "setRolePermission();")
        @Html.ButtonExt("操作权限", "group_key.png", "Role_Actions", "setRoleActions();")
        @Html.ButtonExt("新增", "add.png", "Role_Add", "editRole('add');")
        @Html.ButtonExt("编辑", "edit.png", "Role_Add", "editRole('edit');")
        @Html.ButtonExt("删除", "delete.png", "Role_Del", "DeleteRole();")
       <!--<a onclick="Search()" class="button green"><span class="icon-botton" style="background: url('/Content/16/search.png') no-repeat scroll 0px 4px;">
        </span>查询</a>
        --> 
    </div>
</div>
<!--左侧导航，不用时直接去掉-->
<!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
